#include <stdio.h>
struct Student{
    int num;
    int score;
};
void main()
{
    int i,j,m,n;
    scanf("%d%d",&n,&m);
    struct Student s[m+n],t;
    for(i=0;i<m+n;i++)
    {
        scanf("%d %d",&s[i].num,&s[i].score);
    }
    for(i=0;i<m+n;i++)
    {
        for(j=i+1;j<m+n;j++)
        {
            if(s[i].num>s[j].num)
            {
                t=s[j];
                s[j]=s[i];
                s[i]=t;
            }
        }
    }
    for(i=0;i<m+n;i++)
    {
        printf("%d %d\n",s[i].num,s[i].score);
    }
     
}